<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Cache-Control" content="no-siteapp" />

    <title>xmake v2.2.1 大版本发布，Qt, WDK和Cuda编译环境支持</title>
    <meta name="description" content="为了使xmake更方便灵活地支持其他编译环境，我花了四个多月的时间，对自定义规则rule，进行了大规模升级。现在用户可以通过自定义规则，来实现各种编译规则，并且xmake也内置了一些常用的编译规则，可以直接应用到当前工程，去实现对Qt, WDK驱动和Cuda编译环境的支持。  项目源码  官方文档相关文章介绍： ...">

    
    <meta name="keywords" content="xmake,lua,版本更新,Qt,WDK,Cuda,tboox" /> 

    <!-- qq oauth -->
    <meta property="qc:admins" content="5211601217706727767255" />

    <!--icon -->
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" sizes="192x192" href="/static/img/nice-highres.png" />
	<link rel="apple-touch-icon-precomposed" href="/static/img/apple-touch-icon-57x57-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/img/apple-touch-icon-72x72-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/img/apple-touch-icon-114x114-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/img/apple-touch-icon-144x144-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="180x180" href="/static/img/retinahd_icon.png" />
	<meta name="msapplication-TileImage" content="/static/img/retinahd_icon.png" />
	
    <link rel="stylesheet" href=" /css/fontawesome/css/font-awesome.min.css ">
    <link rel="stylesheet" href=" /css/main.css ">
    <link rel="canonical" href="https://tboox.org/cn/2018/06/17/update-v2.2.1/">
    <link rel="alternate" type="application/rss+xml" title="TBOOX Open Source Project" href="https://tboox.org/feed.xml ">
    <link rel="alternate" hreflang="en" href="https://tboox.org/" />
    <link rel="alternate" hreflang="zh-Hans" href="https://tboox.org/cn/" />

    <!-- css -->
    <link href="/css/reward.css" rel="stylesheet" type="text/css"> 




    <script type="text/javascript">
    function isPC(){    
        var userAgentInfo = navigator.userAgent;  
        var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");    
        var flag = true;    
        for (var v = 0; v < Agents.length; v++) {    
            if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }    
        }    
        return flag;    
    }
    </script>

<!-- baidu ads -->



    <!-- baidu ads -->

</head>


  <body>

    <header id="top">
    <div class="wrapper">
        <a href="/cn" class="brand">TBOOX</a>
        <button id="headerMenu" class="menu"><i class="fa fa-bars"></i></button>
        <nav id="headerNav">
            <ul>
                <li>
                    
                    <a href="/?lang=0">
                    
                        <i class="fa fa-home"></i>English
                    </a>
                </li>

                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/project/">
                            
                        
                            <i class="fa fa-bookmark"></i>项目
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/archive/">
                            
                        
                            <i class="fa fa-archive"></i>归档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/category/">
                            
                        
                            <i class="fa fa-th-list"></i>分类
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/tag/">
                            
                        
                            <i class="fa fa-tags"></i>标记
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/docs/">
                            
                        
                            <i class="fa fa-book"></i>文档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="https://xmake.io/#/zh-cn/about/contact" target="_blank" >
                            
                        
                            <i class="fa fa-forumbee"></i>社区
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/donation/">
                            
                        
                            <i class="fa fa-heart"></i>捐助
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/about/">
                            
                        
                            <i class="fa fa-user"></i>关于
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            </ul>
        </nav>
    </div>
</header>



        <div class="page clearfix" post>
    <div class="left">
        <h1>xmake v2.2.1 大版本发布，Qt, WDK和Cuda编译环境支持</h1>
        <div class="label">

            <div class="label-card">
                <i class="fa fa-calendar"></i>2018-06-17
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
            


<!-- <span class="point">•</span> -->
<span class="categories">
  <i class="fa fa-th-list"></i>
  
    
        <a href="/category/#xmake" title="Category: xmake" rel="category">xmake</a>
    
  

  <!-- <span class="point">•</span> -->
</span>


            </div>

            <div class="label-card">
            
<!-- <span class="point">•</span> -->
<span class="pageTag">
  <i class="fa fa-tags"></i>
  
    
        <!--a href="/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a-->
        <a href="/cn/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a>&nbsp;
    
        <!--a href="/tag/#lua" title="Tag: lua" rel="tag">lua</a-->
        <a href="/cn/tag/#lua" title="Tag: lua" rel="tag">lua</a>&nbsp;
    
        <!--a href="/tag/#%E7%89%88%E6%9C%AC%E6%9B%B4%E6%96%B0" title="Tag: 版本更新" rel="tag">版本更新</a-->
        <a href="/cn/tag/#版本更新" title="Tag: 版本更新" rel="tag">版本更新</a>&nbsp;
    
        <!--a href="/tag/#Qt" title="Tag: Qt" rel="tag">Qt</a-->
        <a href="/cn/tag/#Qt" title="Tag: Qt" rel="tag">Qt</a>&nbsp;
    
        <!--a href="/tag/#WDK" title="Tag: WDK" rel="tag">WDK</a-->
        <a href="/cn/tag/#WDK" title="Tag: WDK" rel="tag">WDK</a>&nbsp;
    
        <!--a href="/tag/#Cuda" title="Tag: Cuda" rel="tag">Cuda</a-->
        <a href="/cn/tag/#Cuda" title="Tag: Cuda" rel="tag">Cuda</a>
    
  

</span>

            </div>

        </div>
        <hr>
        <article itemscope itemtype="http://schema.org/BlogPosting">
        <p>为了使<a href="https://github.com/xmake-io/xmake">xmake</a>更方便灵活地支持其他编译环境，我花了四个多月的时间，对<a href="https://xmake.io/#/zh/manual?id=%E6%9E%84%E5%BB%BA%E8%A7%84%E5%88%99">自定义规则rule</a>，进行了大规模升级。
现在用户可以通过自定义规则，来实现各种编译规则，并且xmake也内置了一些常用的编译规则，可以直接应用到当前工程，去实现对Qt, WDK驱动和Cuda编译环境的支持。</p>

<ul>
  <li><a href="https://github.com/xmake-io/xmake">项目源码</a></li>
  <li><a href="https://xmake.io/#/zh/">官方文档</a></li>
</ul>

<p>相关文章介绍：</p>

<ul>
  <li><a href="http://tboox.org/cn/2018/06/14/support-wdk/">xmake新增对WDK驱动编译环境支持</a></li>
  <li><a href="http://tboox.org/cn/2018/05/30/support-qt/">xmake新增对Qt编译环境支持</a></li>
  <li><a href="http://tboox.org/cn/2018/03/09/support-cuda/">xmake新增对Cuda代码编译支持</a></li>
  <li><a href="http://tboox.org/cn/2017/11/13/custom-rule/">xmake自定义构建规则的使用</a></li>
</ul>

<h3 id="新特性">新特性</h3>

<ul>
  <li><a href="https://github.com/xmake-io/xmake/issues/158">#158</a>: 增加对Cuda编译环境的支持</li>
  <li>添加<code class="highlighter-rouge">set_tools</code>和<code class="highlighter-rouge">add_tools</code>接口为指定target目标设置编译工具链</li>
  <li>添加内建规则：<code class="highlighter-rouge">mode.debug</code>, <code class="highlighter-rouge">mode.release</code>, <code class="highlighter-rouge">mode.profile</code>和<code class="highlighter-rouge">mode.check</code></li>
  <li>添加<code class="highlighter-rouge">is_mode</code>, <code class="highlighter-rouge">is_arch</code> 和<code class="highlighter-rouge">is_plat</code>内置接口到自定义脚本域</li>
  <li>添加color256代码</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/160">#160</a>: 增加对Qt SDK编译环境的跨平台支持，并且增加<code class="highlighter-rouge">qt.console</code>, <code class="highlighter-rouge">qt.application</code>等规则</li>
  <li>添加一些Qt工程模板</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/169">#169</a>: 支持yasm汇编器</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/159">#159</a>: 增加对WDK驱动编译环境支持</li>
</ul>

<h3 id="改进">改进</h3>

<ul>
  <li>添加FAQ到自动生成的xmake.lua文件，方便用户快速上手</li>
  <li>支持Android NDK &gt;= r14的版本</li>
  <li>改进swiftc对warning flags的支持</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/167">#167</a>: 改进自定义规则：<code class="highlighter-rouge">rule()</code></li>
  <li>改进<code class="highlighter-rouge">os.files</code>和<code class="highlighter-rouge">os.dirs</code>接口，加速文件模式匹配</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/171">#171</a>: 改进Qt环境的构建依赖</li>
  <li>在makefile生成插件中实现<code class="highlighter-rouge">make clean</code></li>
</ul>

<h3 id="bugs修复">Bugs修复</h3>

<ul>
  <li>修复无法通过<code class="highlighter-rouge">add_ldflags("xx", "xx", {force = true})</code>强制设置多个flags的问题</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/157">#157</a>: 修复pdb符号输出目录不存在情况下编译失败问题</li>
  <li>修复对macho格式目标strip all符号失效问题</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/168">#168</a>: 修复生成vs201x工程插件，在x64下失败的问题</li>
</ul>

<h3 id="新特性简介">新特性简介</h3>

<h4 id="内置常用规则简化工程描述">内置常用规则简化工程描述</h4>

<p>新版本添加了<code class="highlighter-rouge">mode.debug</code>, <code class="highlighter-rouge">mode.release</code>等内建规则，用于简化常用工程配置，像之前我们在xmake.lua配置debug和release模式编译时候，需要增加下面的配置：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="k">if</span> <span class="n">is_mode</span><span class="p">(</span><span class="s2">"debug"</span><span class="p">)</span> <span class="k">then</span>
    <span class="n">set_symbols</span><span class="p">(</span><span class="s2">"debug"</span><span class="p">)</span>
    <span class="n">set_optimize</span><span class="p">(</span><span class="s2">"none"</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">if</span> <span class="n">is_mode</span><span class="p">(</span><span class="s2">"release"</span><span class="p">)</span> <span class="k">then</span>
    <span class="n">set_symbols</span><span class="p">(</span><span class="s2">"hidden"</span><span class="p">)</span>
    <span class="n">set_optimize</span><span class="p">(</span><span class="s2">"fastest"</span><span class="p">)</span>
    <span class="n">set_strip</span><span class="p">(</span><span class="s2">"all"</span><span class="p">)</span>
<span class="k">end</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
</code></pre>
</div>

<p>在新版本中，就可以简化为：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"mode.debug"</span><span class="p">,</span> <span class="s2">"mode.release"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
</code></pre>
</div>

<p>除了debug和release模式，xmake还提供了profile，check，coverage等编译模式，分别对程序的性能分析、内存检测、覆盖分析提供内置的编译模式。</p>

<h4 id="cuda工程项目支持">Cuda工程项目支持</h4>

<p>更多使用说明请见：<a href="http://tboox.org/cn/2018/03/09/support-cuda/">xmake新增对Cuda代码编译支持</a></p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.cu"</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">sm</span> <span class="k">in</span> <span class="nb">ipairs</span><span class="p">({</span><span class="s2">"30"</span><span class="p">,</span> <span class="s2">"35"</span><span class="p">,</span> <span class="s2">"37"</span><span class="p">,</span> <span class="s2">"50"</span><span class="p">,</span> <span class="s2">"52"</span><span class="p">,</span> <span class="s2">"60"</span><span class="p">,</span> <span class="s2">"61"</span><span class="p">,</span> <span class="s2">"70"</span><span class="p">})</span> <span class="k">do</span>
        <span class="n">add_cuflags</span><span class="p">(</span><span class="s2">"-gencode arch=compute_"</span> <span class="o">..</span> <span class="n">sm</span> <span class="o">..</span> <span class="s2">",code=sm_"</span> <span class="o">..</span> <span class="n">sm</span><span class="p">)</span>
        <span class="n">add_ldflags</span><span class="p">(</span><span class="s2">"-gencode arch=compute_"</span> <span class="o">..</span> <span class="n">sm</span> <span class="o">..</span> <span class="s2">",code=sm_"</span> <span class="o">..</span> <span class="n">sm</span><span class="p">)</span>
    <span class="k">end</span>
    <span class="n">sm</span> <span class="o">=</span> <span class="s2">"70"</span>
    <span class="n">add_cuflags</span><span class="p">(</span><span class="s2">"-gencode arch=compute_"</span> <span class="o">..</span> <span class="n">sm</span> <span class="o">..</span> <span class="s2">",code=compute_"</span> <span class="o">..</span> <span class="n">sm</span><span class="p">)</span>
    <span class="n">add_ldflags</span><span class="p">(</span><span class="s2">"-gencode arch=compute_"</span> <span class="o">..</span> <span class="n">sm</span> <span class="o">..</span> <span class="s2">",code=compute_"</span> <span class="o">..</span> <span class="n">sm</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="qt工程项目支持">Qt工程项目支持</h4>

<p>更多使用说明请见：<a href="http://tboox.org/cn/2018/05/30/support-qt/">xmake新增对Qt编译环境支持</a></p>

<h5 id="quick应用程序">Quick应用程序</h5>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"qt_demo"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"qt.application"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.cpp"</span><span class="p">)</span> 
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/qml.qrc"</span><span class="p">)</span>
    <span class="n">add_frameworks</span><span class="p">(</span><span class="s2">"QtQuick"</span><span class="p">)</span>
</code></pre>
</div>

<h5 id="widgets应用程序">Widgets应用程序</h5>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"qt_widgetapp"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"qt.application"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.cpp"</span><span class="p">)</span> 
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/mainwindow.ui"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/mainwindow.h"</span><span class="p">)</span>  <span class="c1">-- 添加带有 Q_OBJECT 的meta头文件</span>
    <span class="n">add_frameworks</span><span class="p">(</span><span class="s2">"QtWidgets"</span><span class="p">)</span>
</code></pre>
</div>

<h5 id="静态库程序">静态库程序</h5>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"qt.static"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.cpp"</span><span class="p">)</span>
    <span class="n">add_frameworks</span><span class="p">(</span><span class="s2">"QtNetwork"</span><span class="p">,</span> <span class="s2">"QtGui"</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="wdk驱动程序支持">WDK驱动程序支持</h4>

<p>更多使用说明请见：<a href="http://tboox.org/cn/2018/06/14/support-wdk/">xmake新增对WDK驱动编译环境支持</a></p>

<h5 id="umdf驱动程序">umdf驱动程序</h5>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"echo"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"wdk.driver"</span><span class="p">,</span> <span class="s2">"wdk.env.umdf"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"driver/*.c"</span><span class="p">)</span> 
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"driver/*.inx"</span><span class="p">)</span>
    <span class="n">add_includedirs</span><span class="p">(</span><span class="s2">"exe"</span><span class="p">)</span>
</code></pre>
</div>

<h5 id="kmdf驱动程序">kmdf驱动程序</h5>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"nonpnp"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"wdk.driver"</span><span class="p">,</span> <span class="s2">"wdk.env.kmdf"</span><span class="p">)</span>
    <span class="n">add_values</span><span class="p">(</span><span class="s2">"wdk.tracewpp.flags"</span><span class="p">,</span> <span class="s2">"-func:TraceEvents(LEVEL,FLAGS,MSG,...)"</span><span class="p">)</span>
    <span class="n">add_values</span><span class="p">(</span><span class="s2">"wdk.tracewpp.flags"</span><span class="p">,</span> <span class="s2">"-func:Hexdump((LEVEL,FLAGS,MSG,...))"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"driver/*.c"</span><span class="p">,</span> <span class="p">{</span><span class="n">rule</span> <span class="o">=</span> <span class="s2">"wdk.tracewpp"</span><span class="p">})</span> 
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"driver/*.rc"</span><span class="p">)</span>
</code></pre>
</div>

<h5 id="wdm驱动程序">wdm驱动程序</h5>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"kcs"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"wdk.driver"</span><span class="p">,</span> <span class="s2">"wdk.env.wdm"</span><span class="p">)</span>
    <span class="n">add_values</span><span class="p">(</span><span class="s2">"wdk.man.flags"</span><span class="p">,</span> <span class="s2">"-prefix Kcs"</span><span class="p">)</span>
    <span class="n">add_values</span><span class="p">(</span><span class="s2">"wdk.man.resource"</span><span class="p">,</span> <span class="s2">"kcsCounters.rc"</span><span class="p">)</span>
    <span class="n">add_values</span><span class="p">(</span><span class="s2">"wdk.man.header"</span><span class="p">,</span> <span class="s2">"kcsCounters.h"</span><span class="p">)</span>
    <span class="n">add_values</span><span class="p">(</span><span class="s2">"wdk.man.counter_header"</span><span class="p">,</span> <span class="s2">"kcsCounters_counters.h"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"*.c"</span><span class="p">,</span> <span class="s2">"*.rc"</span><span class="p">,</span> <span class="s2">"*.man"</span><span class="p">)</span> 
</code></pre>
</div>

<h5 id="签名驱动程序">签名驱动程序</h5>

<p>测试签名：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"msdsm"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"wdk.driver"</span><span class="p">,</span> <span class="s2">"wdk.env.wdm"</span><span class="p">)</span>
    <span class="n">set_values</span><span class="p">(</span><span class="s2">"wdk.sign.mode"</span><span class="p">,</span> <span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
</code></pre>
</div>

<p>正式签名：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"msdsm"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"wdk.driver"</span><span class="p">,</span> <span class="s2">"wdk.env.wdm"</span><span class="p">)</span>
    <span class="n">set_values</span><span class="p">(</span><span class="s2">"wdk.sign.mode"</span><span class="p">,</span> <span class="s2">"release"</span><span class="p">)</span>
    <span class="n">set_values</span><span class="p">(</span><span class="s2">"wdk.sign.company"</span><span class="p">,</span> <span class="s2">"xxxx"</span><span class="p">)</span>
    <span class="n">set_values</span><span class="p">(</span><span class="s2">"wdk.sign.certfile"</span><span class="p">,</span> <span class="n">path</span><span class="p">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="p">.</span><span class="n">projectdir</span><span class="p">(),</span> <span class="s2">"xxxx.cer"</span><span class="p">))</span>
</code></pre>
</div>

<h3 id="其他特性说明">其他特性说明</h3>

<p>在之前的版本中，用户可以通过<code class="highlighter-rouge">is_plat</code>, <code class="highlighter-rouge">is_arch</code>和<code class="highlighter-rouge">is_mode</code>去快速方便的判断平台、模式、架构，然后去处理不同的配置，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">is_plat</span><span class="p">(</span><span class="s2">"macosx"</span><span class="p">,</span> <span class="s2">"iphoneos"</span><span class="p">)</span> <span class="k">then</span>
        <span class="n">add_defines</span><span class="p">(</span><span class="s2">"TEST"</span><span class="p">)</span>
    <span class="k">end</span>
</code></pre>
</div>

<p>虽然这样更加方便，但是有时候一些更加定制化的需要，仅仅通过外层描述域配置是完成不了的，这个时候用户需要根据自己的需求，实现一些自定义脚本，而这些api之前是没法在自定义脚本中使用。</p>

<p>而在新版本中，xmake对这些常用api在自定义脚本中进行了扩充，现在也能直接调用来简化脚本实现：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">on_load</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">target</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">is_plat</span><span class="p">(</span><span class="s2">"macosx"</span><span class="p">,</span> <span class="s2">"iphoneos"</span><span class="p">)</span> <span class="k">then</span>
            <span class="n">target</span><span class="p">:</span><span class="n">add</span><span class="p">(</span><span class="s2">"defines"</span><span class="p">,</span> <span class="s2">"TEST"</span><span class="p">)</span>
        <span class="k">end</span>
        <span class="k">if</span> <span class="n">is_mode</span><span class="p">(</span><span class="s2">"debug"</span><span class="p">)</span> <span class="k">then</span>
            <span class="n">target</span><span class="p">:</span><span class="n">add</span><span class="p">(</span><span class="s2">"defines"</span><span class="p">,</span> <span class="s2">"DEBUG"</span><span class="p">)</span>
        <span class="k">end</span>
    <span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

        </article>
        <hr>

        <!-- baidu ads -->
        

        <!-- reward -->
        <div style="text-align: center;">
            <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
              <span>赏</span>
            </button>
            <div id="QR" style="display: none;">
                <div id="wechat" style="display: inline-block">
                  <img id="wechat_qr" src="/static/img/weixin.png" alt="WeChat Pay"/>
                  <p>微信打赏</p>
                </div>
                <div id="alipay" style="display: inline-block">
                  <img id="alipay_qr" src="/static/img/alipay.png" alt="Alipay"/>
                  <p>支付宝打赏</p>
                </div>
            </div>
        </div>

        
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
                    
                    <h2 id="english">English</h2>
                    <ul>
                    
                    <li class="relatedPost">
                        <a href="/2018/06/17/update-v2.2.1/">xmake v2.2.1 released, Support Qt, WDK and Cuda Compilation Environments
                        
                        </a>
                    </li>
                    
                    
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
        
            </ul>
        

        
        
            
        
            
            
            
                
                    
                        
                        <h2 id="similar_posts">相关文章</h2>
                        <ul>
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/17/xmake-update-v2.6.2/">xmake v2.6.2 发布，新增 Linux 内核驱动模块构建支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/03/xmake-update-v2.6.1/">xmake v2.6.1 发布，使用 Lua5.4 运行时，Rust 和 C++ 混合编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/10/30/xmake-update-v2.5.9/">xmake v2.5.9 发布，改进 C++20 模块，并支持 Nim, Keil MDK 和 Unity Build
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/10/08/xmake-update-v2.5.8/">xmake v2.5.8 发布，新增 Pascal/Swig 程序和 Lua53 运行时支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/08/29/xmake-update-v2.5.7/">xmake v2.5.7 发布，包依赖锁定和 Vala/Metal 语言编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
        
            </ul>
        

        <div class="post-recent">
    <div class="pre">

        

        

        
        
        <p><strong>上一篇</strong> <a href="/cn/2018/06/14/support-wdk/">xmake新增对WDK驱动编译环境支持</a></p>
        
    </div>

    <div class="nex">

        

        

        
        
        

        

        

        
        
        <p><strong>下一篇</strong> <a href="/cn/2018/06/25/xmake-vscode-update-v1.0.8/">xmake-vscode v1.0.8版本发布，在vscode中构建Qt/WDK程序</a></p>
        
    </div>
</div>


        <h2 id="comments">评论</h2>
        






<div id="gitalk-container"></div>
<link rel="stylesheet" href="/css/gitalk.css">
<script src="/js/gitalk.min.js"></script>

<script>
const gitalk = new Gitalk({
  clientID: '73946dc1d9e2276ad0da',
  clientSecret: '12a3cb94361ba3ebc6ecb68cf80d592bfaa8106d',
  repo: 'tboox.github.io',
  owner: 'waruqi',
  admin: ['waruqi'],
  id: location.pathname,       
  language: 'zh-CN',
  distractionFreeMode: false  
})

gitalk.render('gitalk-container')
</script>





    </div>
    <button class="anchor"><i class="fa fa-anchor"></i></button>
    <div class="right">
        <div class="wrap">

            <!-- codefund ads -->
            

            <!-- Content -->
            <div class="side content">
                <div>
                    内容
                </div>
                <ul id="content-side" class="content-ul">
                    <li><a href="#english">English</a></li>
                    <li><a href="#similar_posts">相关文章</a></li>
                    <li><a href="#comments">评论</a></li>
                </ul>
            </div>


            <!-- baidu ads -->
            
            
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    链接
                </div>
                <ul class="content-ul">
                  <li><a href="http://github.com/waruqi/tbox">tbox</a></li>
                  <li><a href="http://www.xmake.io">xmake</a></li>
                  <li><a href="https://github.com/waruqi">github</a></li>
                </ul>
            </div> 

            <!-- xmake courses -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    xmake 入门课程
                </div>
                <a href="https://xmake.io/#/zh-cn/about/course" target="_blank">
                <img src="/static/img/xmake-course.png" alt="course" width="256" height="193">
                </a>
            </div>

            <!-- qqgroup -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    技术交流群（QQ）
                </div>
                <img src="/static/img/qqgroup.png" alt="qqgroup" width="256" height="284">
            </div> 

            <!-- google ads -->
            

            <!-- baidu ads -->
            

        </div>
    </div>

    <!-- baidu ads -->
    
</div>
<script>
/**
 * target _blank
 */
(function() {
    var aTags = document.querySelectorAll('article a:not([id])')
    for (var i = 0; i < aTags.length; i++) {
        aTags[i].setAttribute('target', '_blank')
    }
}());
</script>
<script src="/js/pageContent.js " charset="utf-8"></script>



    <footer class="site-footer">
    <div class="wrapper">
        <p class="description">
             Copyright (c) 2016-2020 tboox.org 
        </p>
        <p class="contact">
            
            <a href="https://github.com/waruqi" title="GitHub"><i class="fa fa-github" aria-hidden="true"></i></a> 
             
            
            <a href="mailto:waruqi@gmail.com" title="email"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> 
            
            
            <a href="https://twitter.com/waruqi" title="Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a> 
            
            <a href="/feed.xml" title="feed"><i class="fa fa-feed" aria-hidden="true"></i></a> 
        </p>
        <p class="power">
            <span>
                Site powered by <a href="https://jekyllrb.com/">Jekyll</a> & <a href="https://github.com/Gaohaoyang">HyG</a> & <a href="https://pages.github.com/">Github Pages</a>.
            </span>
        </p>
    </div>
</footer>

    <div class="back-to-top">
    <a href="#top" class="scroll">
        <i class="fa fa-arrow-up" aria-hidden="true"></i>
    </a>
</div>

    <script src=" /js/main.js " charset="utf-8"></script>
    <script src=" /js/scroll.min.js " charset="utf-8"></script>
  </body>

</html>
